﻿// -----------------------------------------------------------------------
// <copyright file="MembershipAdapter.cs" company="CompDJ">
//     Copyright (c) CompDJ. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace CompDJ.Web.Abstractions
{
    using System.Web.Security;

    /// <summary>Membership adapter.</summary>
    /// <remarks>By default, this class cannot be unit tested, as it is an 
    /// adapter for the real thing. Plus, there is no actual logic in here.</remarks>
    [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
    public partial class MembershipAdapter : IMembership
    {
        /// <summary>Initializes a new instance of the MembershipAdapter class.</summary>
        public MembershipAdapter()
        {
            Membership.ValidatingPassword += Membership_ValidatingPassword;
        }

        void Membership_ValidatingPassword(object sender, ValidatePasswordEventArgs e)
        {
            this.ValidatingPassword.Invoke(sender, e);
        }
        
        public virtual string ApplicationName
        {
            get
            {
                return Membership.ApplicationName;
            }
            set
            {
                Membership.ApplicationName = value;
            }
        }

        public virtual bool EnablePasswordReset
        {
            get { return Membership.EnablePasswordReset; }
        }

        public virtual bool EnablePasswordRetrieval
        {
            get { return Membership.EnablePasswordRetrieval; }
        }

        public virtual string HashAlgorithmType
        {
            get { return Membership.HashAlgorithmType; }
        }

        public virtual int MaxInvalidPasswordAttempts
        {
            get { return Membership.MaxInvalidPasswordAttempts; }
        }

        public virtual int MinRequiredNonAlphanumericCharacters
        {
            get { return Membership.MinRequiredNonAlphanumericCharacters; }
        }

        public virtual int MinRequiredPasswordLength
        {
            get { return Membership.MinRequiredPasswordLength; }
        }

        public virtual int PasswordAttemptWindow
        {
            get { return Membership.PasswordAttemptWindow; }
        }

        public virtual string PasswordStrengthRegularExpression
        {
            get { return Membership.PasswordStrengthRegularExpression; }
        }

        public virtual MembershipProvider Provider
        {
            get { return Membership.Provider; }
        }

        public virtual MembershipProviderCollection Providers
        {
            get { return Membership.Providers; }
        }

        public virtual bool RequiresQuestionAndAnswer
        {
            get { return Membership.RequiresQuestionAndAnswer; }
        }

        public virtual int UserIsOnlineTimeWindow
        {
            get { return Membership.UserIsOnlineTimeWindow; }
        }

        public virtual event MembershipValidatePasswordEventHandler ValidatingPassword;

        public virtual MembershipUser CreateUser(string username, string password)
        {
            return Membership.CreateUser(username, password);
        }

        public virtual MembershipUser CreateUser(string username, string password, string email)
        {
            return Membership.CreateUser(username, password, email);
        }

        public virtual MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, out MembershipCreateStatus status)
        {
            return Membership.CreateUser(username, password, email, passwordQuestion, passwordAnswer, isApproved, out status);
        }

        public virtual MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            return Membership.CreateUser(username, password, email, passwordQuestion, passwordAnswer, isApproved, providerUserKey, out status);
        }

        public virtual bool DeleteUser(string username)
        {
            return Membership.DeleteUser(username);
        }

        public virtual bool DeleteUser(string username, bool deleteAllRelatedData)
        {
            return Membership.DeleteUser(username, deleteAllRelatedData);
        }

        public virtual MembershipUserCollection FindUsersByEmail(string emailToMatch)
        {
            return Membership.FindUsersByEmail(emailToMatch);
        }

        public virtual MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords)
        {
            return Membership.FindUsersByEmail(emailToMatch, pageIndex, pageSize, out totalRecords);
        }

        public virtual MembershipUserCollection FindUsersByName(string usernameToMatch)
        {
            return Membership.FindUsersByName(usernameToMatch);
        }

        public virtual MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
        {
            return Membership.FindUsersByName(usernameToMatch, pageIndex, pageSize, out totalRecords);
        }

        public virtual string GeneratePassword(int length, int numberOfNonAlphanumericCharacters)
        {
            return Membership.GeneratePassword(length, numberOfNonAlphanumericCharacters);
        }

        public virtual MembershipUserCollection GetAllUsers()
        {
            return Membership.GetAllUsers();
        }

        public virtual MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
        {
            return Membership.GetAllUsers(pageIndex, pageSize, out totalRecords);
        }

        public virtual int GetNumberOfUsersOnline()
        {
            return Membership.GetNumberOfUsersOnline();
        }

        public virtual MembershipUser GetUser()
        {
            return Membership.GetUser();
        }

        public virtual MembershipUser GetUser(bool userIsOnline)
        {
            return Membership.GetUser(userIsOnline);
        }

        public virtual MembershipUser GetUser(object providerUserKey)
        {
            return Membership.GetUser(providerUserKey);
        }

        public virtual MembershipUser GetUser(string username)
        {
            return Membership.GetUser(username);
        }

        public virtual MembershipUser GetUser(object providerUserKey, bool userIsOnline)
        {
            return Membership.GetUser(providerUserKey, userIsOnline);
        }

        public virtual MembershipUser GetUser(string username, bool userIsOnline)
        {
            return Membership.GetUser(username, userIsOnline);
        }

        public virtual string GetUserNameByEmail(string emailToMatch)
        {
            return Membership.GetUserNameByEmail(emailToMatch);
        }

        public virtual void UpdateUser(MembershipUser user)
        {
            Membership.UpdateUser(user);
        }

        public virtual bool ValidateUser(string username, string password)
        {
            return Membership.ValidateUser(username, password);
        }
    }
}
